package com.blacktry.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blacktry.entity.enums.OprLogConst;
import com.blacktry.entity.model.ApiResult;
import com.blacktry.entity.model.Calendar;

import com.blacktry.entity.model.request.CalendarRequest;
import com.blacktry.service.CalendarService;
import com.blacktry.utils.ApiResultHandler;
import com.blacktry.utils.log.OperLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Api(value = "教学日历模块", tags = "教学日历接口")
@RestController
@RequestMapping("/calendar")

public class CalendarController {

    @Autowired
    private CalendarService calendarService;

    //查看一个老师的所有教学日历
    @OperLog(operModul = "教学日历管理-查看一个老师的所有教学日历",operType = OprLogConst.SELECT,operDesc = "查看一个老师的所有教学日历功能")
    @ApiOperation("查看一个老师的所有教学日历")
    @PostMapping("/selectCalendar/{page}/{size}")
    public ApiResult<Page<Calendar>> select(@PathVariable Integer page, @PathVariable Integer size, @RequestBody CalendarRequest calendarRequest) {
        return ApiResultHandler.buildApiResult(200, "成功", calendarService.selectCalendar(calendarRequest, new Page<Calendar>(page, size)));
    }

    @OperLog(operModul = "教学日历管理-导出教学日历",operType = OprLogConst.SELECT,operDesc = "导出教学日历功能")
    @ApiOperation("导出教学日历")
    @GetMapping("/exportCalendar")
    public void exportCalendar(HttpServletResponse response, @RequestParam("id") int id, @RequestParam("username") String username) throws IOException {
        System.out.println("开始导出教学日历===>"+username+"........"+id);
        CalendarRequest calendarRequest = new CalendarRequest();
        calendarRequest.setId(id);
        calendarRequest.setUsername(username);
        calendarService.exportCalendar(response,calendarRequest);
    }

}
